<?php


class order extends CI_Controller {
	
	var $user = array('user_name'=>'admini', 'pwd'=>'6apcin842fy');
	var $data = array();
	
	public function __construct() {
	
		parent::__construct();
		$this->load->database();
		
		$this->data['status'] = array('verify'=>'正在核实中', 'processed'=>'订单已核实', 'wait'=>'等候配送中', 'complete'=>'订单完成', 'invalid'=>'无效订单');
		$this->load->model('order_mod');
		$this->load->helper('url');
	}
	
	public function index() {	
		
		$order_time_start = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
		$order_time_end = mktime(11, 59, 59, date('m'), date('d'), date('Y'));		
		$this->db->select('*')->from('order');
		//状态
		$OrderStatus = $this->input->get('s');
		if(!$OrderStatus) {
			$this->db->where_in('order_status', array('verify','processed','wait'));
		} else {
			$this->db->where('order_status', $OrderStatus);
		}
		
		//手机号
		$mobile = $this->input->get('m');
		if($mobile) {
			$this->db->where('Phone', $mobile);
		}
		
		$this->db->where('unix_timestamp(OrderTime) >', $order_time_start);
		$this->db->where('unix_timestamp(OrderTime) <', $order_time_end);
		$this->db->order_by('OrdID', 'DESC');
		$query = $this->db->get();
		
		if($query->num_rows() > 0) {
		
			$this->data['order'] = $query->result_array();
		} else {
			
			$this->data['order'] = FALSE;
		}
	
		$this->load->view('order', $this->data);
	}
	
	public function ajax_order_status($OrderNumber, $OrderStatus) {
		if($this->order_mod->updateOrderStatus($OrderNumber, $OrderStatus)) {
			
			echo json_encode(array('code'=>1000, 'msg'=>$OrderNumber.','.$this->data['status'][$OrderStatus].'成功', 'data'=>$this->data['status'][$OrderStatus]));
			exit;
		} else {
		
			echo json_encode(array('code'=>1001, 'msg'=>'状态更新失败', 'data'=>$OrderNumber));
			exit;
		}
		
	
	}

}